#! /bin/bash
#   
# mongodb:    mongodb Daemon   
#   
# chkconfig:    - 90 25  
# description:  mongodb Daemon   
#   
### BEGIN INIT INFO
# Provides:          mongodb
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Should-Start:        $local_fs
# Should-Stop:        $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description:    mongodb - Memory caching daemon
# Description:        mongodb - Memory caching daemon
### END INIT INFO

PORT=27017
USER=root
MONGODBDIR="/usr/local/mongodb2.0.4"
DBDIR="/home/mongodb/mongodb_db"
LOGDIR="/home/mongodb/mongodb_logs"

RETVAL=0
prog="mongodb"

start () {
    echo -n $"Starting $prog: "
    nohup mongod --dbpath $DBDIR --port $PORT --logpath $LOGDIR --logappend  > /dev/null 2>&1 &
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongodb
}
stop () {
    echo -n $"Stopping $prog: "
    pkill mongod
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ] ; then
        rm -f /var/lock/subsys/mongodb
    fi
}

restart () {
    stop
    start
}

status () {
    mongod
}

[ "$1" == '' ] && start && exit;
# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
    stop
    ;;
    restart|reload)
    restart
    ;;
    *)
    echo $"Usage: $0 {start|stop|status|restart|reload}"
    exit 1
esac

exit $?